package userController

import (
	"gin/common"
	"net/http"
	"strconv"

	"github.com/gin-gonic/gin"
)

func GetInfo(ctx *gin.Context) {
	userName := ctx.Query("name")
	userAgeStr := ctx.Query("age")

	// 将 age 从字符串转换为整数
	userAge, err := strconv.Atoi(userAgeStr)
	if err != nil {
		// 如果转换失败，返回错误响应
		ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid age parameter"})
		return
	}

	userInfo := common.User{
		Name: userName,
		Age:  userAge,
	}
	ctx.JSON(http.StatusOK, common.Ok(userInfo))
}
